package model;

import persistence.PersistableInterface;

import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.awt.Color;

/**
 * Created with IntelliJ IDEA.
 * User: david
 * Date: 8/8/13
 * Time: 12:05 PM
 *
 * Class for storing metadata about a {@code Material} such as name, manufacturer and website.
 *
 */
@Embeddable
public class MaterialMetaData implements PersistableInterface {
    @Id
    @GeneratedValue
    private Long id;
    private String name;
    private String manufacturer;
    private String website;
    private String comments;
    private Color color;

    /**
     * Creates the Meta data for a material
     * @param id
     * @param name
     * @param manufacturer
     * @param website
     * @param comments
     */
    public MaterialMetaData(Long id, String name, String manufacturer, String website, String comments, Color color){
        if(name == null){ name = "";}
        if(manufacturer == null){ manufacturer = "";}
        if(website == null){ website = "";}
        if(comments == null){ comments = "";}
        this.id = id;
        this.name = name;
        this.manufacturer = manufacturer;
        this.website = website;
        this.comments = comments;
        this.color = color;
    }

    public MaterialMetaData(String name, String manufacturer, String website, String comments, Color color){
        if(name == null){ name = "";}
        if(manufacturer == null){ manufacturer = "";}
        if(website == null){ website = "";}
        if(comments == null){ comments = "";}
        this.name = name;
        this.manufacturer = manufacturer;
        this.website = website;
        this.comments = comments;
        this.color = color;
    }

    public MaterialMetaData(String name, String manufacturer, String website){
        if(name == null){ name = "";}
        if(manufacturer == null){ manufacturer = "";}
        if(website == null){ website = "";}
        this.name = name;
        this.manufacturer = manufacturer;
        this.website = website;
        this.comments = "";
    }

    public MaterialMetaData(String name, String manufacturer, Color color){
        if(name == null) name = "";
        if(manufacturer == null) manufacturer = "";

        this.name = name;
        this.manufacturer = manufacturer;
        this.color = color;

        this.website = "";
        this.comments = "";

    }

    protected MaterialMetaData(){
        //required for jpa
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name == null){ name = "";}
        this.name = name;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        if(manufacturer == null){ manufacturer = "";}
        this.manufacturer = manufacturer;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        if(website == null){ website = "";}
        this.website = website;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        if(comments == null){ comments = "";}
        this.comments = comments;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    @Override
    public String toString(){
        return name + ", " + manufacturer + ", " + comments;
    }
}
